﻿<local:BaseListWithToolbarContentFrame x:Class="InfFront.InfoViews.WPF.ListViewFrame"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:InfFront.InfoViews.WPF"
    Height="Auto" Width="Auto" MinWidth="300" MinHeight="300"
    >

    <UserControl.Resources>
        <local:IconedObjectToNormal48x48ImageConverter x:Key="getNormalImage"/>

        <Style x:Key="listViewStyle" TargetType="{x:Type ListView}" 
               BasedOn="{StaticResource {x:Type ListBox}}">
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="ItemContainerStyle" 
                    Value="{Binding (ListView.View).ItemContainerStyle, RelativeSource={RelativeSource Self}}"/>
            <Setter Property="ItemTemplate" 
                    Value="{Binding (ListView.View).ItemTemplate, RelativeSource={RelativeSource Self}}"/>
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <WrapPanel Width="{Binding (FrameworkElement.ActualWidth),RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
                                   ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}"
                                   MinWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}"
                                   ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}"/>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    
        <DataTemplate x:Key="centralTile">
            <StackPanel Height="100" Width="80">
                <Grid Width="60" Height="63" HorizontalAlignment="Center">
                    <Image Source="{Binding Converter={StaticResource getNormalImage}}" Margin="6,6,6,9"/>
                </Grid>
                <TextBlock Text="{Binding}" HorizontalAlignment="Center" Margin="0,0,0,1" 
                           TextWrapping="Wrap" TextAlignment="Center" />
            </StackPanel>
        </DataTemplate>

        <local:PlainView x:Key="iconsView" 
                         ItemTemplate="{StaticResource centralTile}" 
                         ItemWidth="100"
                         />

    </UserControl.Resources>
    
    <UserControl.Background>
        <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
            <GradientStop Offset="0" Color="{Binding Path=VisualSettings.PrimaryGridColor, FallbackValue=White}"/>
            <GradientStop Offset="1" Color="{Binding Path=VisualSettings.SecondaryGridColor, FallbackValue=Azure}"/>
        </LinearGradientBrush>
    </UserControl.Background>

    <ListView Name="listView"
              SelectionChanged="listView_SelectionChanged"
              SelectionMode="Single"
              Style="{StaticResource listViewStyle}"
              View="{StaticResource iconsView}"
              Background="Transparent"
              />

</local:BaseListWithToolbarContentFrame>
